export class RedBlackTreeNode<K, V> {
	#isRed: boolean = false

	#isNIL: boolean = false

	size: number = 0

	leftChild: RedBlackTreeNode<K, V> = undefined

	parent: RedBlackTreeNode<K, V> = undefined

	rightChild: RedBlackTreeNode<K, V> = undefined

	constructor(public key: K, public value: V, nil: RedBlackTreeNode<K, V>) {
		this.#isNIL = nil === undefined
		this.reset(nil || this)
	}

	get isRed(): boolean {
		if (this.#isNIL) {
			return false
		}

		return this.#isRed
	}

	set isRed(value: boolean) {
		if (!this.#isNIL) {
			this.#isRed = value
		}
	}

	get isBlack(): boolean {
		if (this.#isNIL) {
			return true
		}

		return !this.#isRed
	}

	set isBlack(value: boolean) {
		if (!this.#isNIL) {
			this.#isRed = !value
		}
	}

	private reset(nil: RedBlackTreeNode<K, V>): void {
		this.leftChild = nil
		this.parent = nil
		this.rightChild = nil
	}

	copyAttributesTo(to: RedBlackTreeNode<K, V>): void {
		to.key = this.key
		to.value = this.value
		to.#isRed = this.#isRed
	}
}
